<!--待办中心&#45;&#45;待执行任务&#45;&#45;申请完成（单条项目申请）-->
<template>
  <a-drawer
    title="申请完成"
    :width="720"
    :visible="drawerVisible"
    :maskClosable="drawMaskClosable"
    :body-style="{ paddingBottom: '80px' }"
    @close="closeApplyComplete"
  >
    <a-row>
      <span style="color: red">*&nbsp;&nbsp;</span><span>完成百分比：</span>
      <a-input-number
        v-model="perc"
        :min="0"
        :max="100"
        style="width: 100%; margin: 8px 0px 8px 0px"
      />
    </a-row>
    <a-row>
      <span>完成情况说明：</span>
      <a-textarea
        style="width: 100%; margin: 8px 0px 8px 0px"
        v-model="textareaValue"
        :auto-size="{ minRows: 3, maxRows: 10 }"
      />
    </a-row>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '10px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1,
      }"
    >
      <a-button :style="{ marginRight: '8px' }" @click="closeApplyComplete">
        取消
      </a-button>
      <a-button type="primary" @click="commitApplyComplete"> 确认 </a-button>
    </div>
  </a-drawer>
</template>
<script>
import { getLastResourceHour, sumResource } from "@api/todoPage";
export default {
  name: "applyCompleteOnce",
  data() {
    return {
      drawerVisible: this.drawerVisible_p,
      textareaValue: "",
      modalAreaValue: "",
      selectDefaultValue: "请选择",
      selectData: [], //下拉框数
      modalVisible: false,
      perc: null, //完成百分比
      minPerc: 0, //完成百分比最小值
      // days: 0,//实际工期
    };
  },
  props: {
    drawerVisible_p: {
      type: Boolean,
      default: false,
    },
    assignmentOid: {
      type: String,
      default: "",
    },
    drawMaskClosable: {
      type: Boolean,
      default: false,
    }, //点击蒙层是否允许关闭
  },
  computed: {},
  watch: {
    drawerVisible_p(val) {
      this.perc = null;
      // this.days = null
      this.drawerVisible = val;
    },
  },
  mounted() {
    // console.log('当前的assignmentOid：', this.assignmentOid)
    this.getLastResourceHourB();
  },
  methods: {
    handleChange(value) {
      // 点击下拉框
      // this.$emit('selectChange', value)
      this.textareaValue = value;
    },
    handleOk(e) {
      this.modalVisible = false;
    },
    showModal() {
      this.modalVisible = true;
    },
    //关闭抽屉
    closeApplyComplete() {
      this.$emit("closeDraw");
    },
    //获取上一次汇报工时的记录
    getLastResourceHourB() {
      let parm = {
        resources: [
          {
            assignmentOid: this.assignmentOid,
          },
        ],
      };
      getLastResourceHour(parm).then((res) => {
        if (res && res.status === 200) {
          if (res.data && res.data.success == true) {
            if (res.data.data && res.data.data.length > 0) {
              this.perc = res.data.data[0].completePercent;
              this.minPerc = res.data.data[0].completePercent;
              // this.days = res.data.data[0].completeTime
              this.textareaValue = "";
            } else {
              this.perc = 100;
              this.minPerc = null;
              // this.days = null
              this.textareaValue = "";
            }
          } else {
            this.$message.error(res.data.message);
          }
        } else {
          this.$message.error("接口失败");
        }
      });
    },
    //完成审核，关闭抽屉
    commitApplyComplete() {
      // console.log('当前this.assignmentOid：', this.assignmentOid)
      // if (this.perc == '' || this.days == '' || this.textareaValue == '') {
      //   this.$message.success('请输入必需项！')
      // }
      // if (this.perc == null) {
      //   this.$message.warn('请输入必需项！');return;
      // }else {
      // let parm = {
      //   resources: [
      //     {
      //       assignmentOid: this.assignmentOid,
      //       completePercent: parseInt(this.perc),
      //       completeTime: parseInt(this.days),
      //       comment: this.textareaValue
      //     }
      //   ]
      // }
      let parm = {
        resources: [
          {
            assignmentOid: this.assignmentOid,
            completePercent: parseInt(this.perc),
            // completeTime: parseInt(this.days),
            comment: this.textareaValue || "工作已完成，申请关闭",
          },
        ],
      };
      console.log(parm, this.perc);
      sumResource(parm).then((res) => {
        if (res && res.status === 200) {
          if (res.data.success == true) {
            this.$message.success("申请成功！");
            this.perc = null;
            this.minPerc = null;
            // this.days = null
            this.textareaValue = "";
            this.$store.commit("commitApplyAdd"); //刷新抽屉中的数据
            this.$emit("closeDraw");
            this.$store.commit("clearSelectedTableData"); //关闭抽屉后清空选中的数组
          } else {
            this.$message.error(res.data.message);
          }
        } else {
          this.$message.error("接口连接失败！");
        }
      });
      // }
    },
  },
};
</script>
<style scoped lang="less">
.applyDraw_temp {
  /deep/ .ant-row {
    margin-bottom: 10px;
  }
  /deep/ .ant-drawer-content-wrapper {
    width: 520px !important;
  }
}
.selectBox {
  display: flex;
  align-items: center;
  margin-top: 1.5vh;
  .selectConetnt,
  .custom {
    margin-right: 1vw;
  }
}
.textArae {
  margin-top: 1.5vh;
  .submit {
    margin-top: 10px;
    width: 170px;
    color: #fff;
    //background-color: #386bd7;
    padding: 0px;
    border-radius: 4px;
  }
}
</style>